package com.visutech.common;

import java.util.List;



/**
 * 翻页处理用工具bean
 * Created by 程振奇 on 15/10/12.
 */
public class PageBean<T> {
    private int pageNo = 1;
    private int pageSize = 20;
    private int totalCount;
    private int totalPage;
    private List<T> data;
    private int offset;

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }
    public boolean haveNextPage(){
        return pageNo<totalPage;
    }
    public boolean havePrevPage(){
        return pageNo>1;
    }
    public int getNextPageNo(){
        return pageNo+1;
    }
    public int getPrevPageNo(){
        return pageNo-1<1?1:(pageNo-1);
    }
    public int getPageNo() {
        return pageNo<=0?1:pageNo;
    }
    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }
    public int getPageSize() {
        return pageSize;
        /*return pageSize*pageNo;*/
    }
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
        this.totalPage = totalCount<=0?1:(totalCount+pageSize-1)/pageSize;
    }
    public int getTotalCount() {
        return totalCount;
    }
    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
        this.totalPage = totalCount<=0?1:(totalCount+pageSize-1)/pageSize;
    }
    public int getTotalPage() {
        return totalPage;
    }

    public int getOffset() {
        this.setOffset(offset = (pageNo - 1) * pageSize);
        return offset;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }
}